<?php defined("MAIN_DIR") or die("No direct access");

$id = $route->POST("id");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_COOKIE['sess_id'])){
    $session_id = $_COOKIE['sess_id'];
} else {
    $session_id = md5(time().rand(0,100));
    setcookie("sess_id",$session_id,0,"/");
}

$is_vote = $db->getCell("select count(`id`) from `ratings` where `quote_id` = '$id' and (`ip` = '$ip' or `session_id` = '$session_id')");
if (!$is_vote) {
    
    $query = "insert into `ratings` values (NULL,'$id','1','$ip','$session_id')";
    $db->sendQuery($query);
}

echo $db->getCell("select COUNT(`id`) from `ratings` where `quote_id` = '$id'");

?>
